/* rcslb01.p - DO ALLOCATIONS FOR A SCHEDULED ORDER LINE AND STAGE         */
/* Copyright 1986-2002 QAD Inc., Carpinteria, CA, USA.                     */
/* All rights reserved worldwide.  This is an unpublished work.            */
/*V8:ConvertMode=NoConvert                                                 */
/* REVISION: 7.5    LAST MODIFIED: 01/02/96           BY: GWM *J049*       */
/* REVISION: 8.6    LAST MODIFIED: 09/16/96   BY: *K003* Vinay Nayak-Sujir */
/* REVISION: 8.6    LAST MODIFIED: 10/02/96   BY: *K003* forrest mori      */
/* REVISION: 8.6E   LAST MODIFIED: 02/23/98   BY: *L007* A. Rahane         */
/* REVISION: 8.6E   LAST MODIFIED: 05/20/98   BY: *K1Q4* Alfred Tan        */
/* REVISION: 8.6E   LAST MODIFIED: 06/07/98   BY: *J2MH* Dana Tunstall     */
/* REVISION: 9.1    LAST MODIFIED: 06/14/99   BY: *N004* Patrick Rowan     */
/* REVISION: 9.1    LAST MODIFIED: 12/02/99   BY: *L0M0* Manish  K.        */
/* REVISION: 9.1    LAST MODIFIED: 08/12/00   BY: *N0KP* Mark Brown        */
/* REVISION: 9.1    LAST MODIFIED: 09/06/00   BY: *N0RG* Mudit Mehta       */

         {mfdeclre.i}
/*N0RG*/ {gplabel.i} /* EXTERNAL LABEL INCLUDE */

/* ********** Begin Translatable Strings Definitions ********* */

/*N0RG***********BEGIN COMMENTING*************
 * &SCOPED-DEFINE rcslb01_p_1 "'For Sales Orders'"
 * /* MaxLen: Comment: */
 *
 * &SCOPED-DEFINE rcslb01_p_2 "'For Remote Inventory'"
 * /* MaxLen: Comment: */
 *N0RG***********END COMMENTING************* */

/* ********** End Translatable Strings Definitions ********* */


         /* INPUT VARIABLES */
         define input parameter so_recid as recid no-undo.
         define input parameter sod_recid as recid no-undo.
         define input parameter all_only as logical no-undo.
         define input parameter alloc_cont as logical no-undo.
         define input parameter open_qty like sod_qty_ord no-undo.
/*K003*/ define input parameter shipgrp like sg_grp no-undo.
/*K003*/ define input parameter inv_mov like abs_inv_mov no-undo.
/*K003*/ define input parameter nrseq like abs_preship_nr_id no-undo.
/*K003*/ define input parameter cons_ship like abs_cons_ship no-undo.
/*J2MH*/ define input parameter l_create_um like mfc_logical  no-undo.
         define output parameter abnormal_exit as logical no-undo.

         /* LOCAL VARIABLES */
         define variable so_db like si_db no-undo.
         define variable err_flag as integer no-undo.
         define variable total_alloc like lad_qty_all no-undo.
/*L0M0*/ define variable l_delproc like mfc_logical no-undo.

         /* SHARED VARIABLES FOR SOPKALL.P */
         define new shared variable alc_sod_nbr like sod_nbr.
         define new shared variable alc_sod_line like sod_line.
         define new shared variable tot_qty_all like lad_qty_all.
         define new shared variable sod_recno as recid.
         define new shared variable so_recno as recid.

/*N004*/ /* SHARED VARIABLES FOR CUSTOMER SEQUENCE SCHEDULES */
/*N004*/ {sosqvars.i}

         find sod_det where recid(sod_det) = sod_recid.

         assign
         so_db = global_db
         alc_sod_nbr = sod_nbr
         alc_sod_line = sod_line
         sod_recno = sod_recid
         so_recno = so_recid.

         /*CREATE HARD ALLOCATIONS IN THE INVENTORY SITE*/
         if sod_type = "" then do:

            /* SWITCH TO THE INVENTORY SITE */
            {gprun.i ""gpalias2.p"" "(input sod_site, output err_flag)"}

            if err_flag <> 0 and err_flag <> 9 then do:

               /* DATABASE # IS NOT CONNECTED */
/*N0RG*        {mfmsg03.i 2510 4 {&rcslb01_p_2} """" """"} */
/*N0RG*/       {pxmsg.i &MSGNUM=2510 &ERRORLEVEL=4
                        &MSGARG1=getTermLabel(""FOR_REMOTE_INVENTORY"",25)}
               abnormal_exit = true.
               return.
            end.


            /* DO THE DETAIL ALLOCATIONS */
            {gprun.i ""sopkall.p""}


/*K003*/    /* Added shipgrp, inv_mov, nrseq, cons_ship */
        /* CREATE THE STAGE LIST LINES */
/*J2MH*/    /* ADDED INPUT PARAMETER L_CREATE_UM */
            {gprun.i ""sosle01.p""
                     "(input sod_nbr,
                       input sod_line,
                       input alloc_cont,
                       input so_db,
                       input shipgrp,
                       input inv_mov,
                       input nrseq,
                       input cons_ship,
                       input l_create_um,
                       output total_alloc,
                      output abnormal_exit)"}



            /* HANDLE ABNORMAL EXIT FLAG */
            if abnormal_exit then return.

            /* SET TOT_QTY_ALL FOR SOSOPKA2.P */
            tot_qty_all = total_alloc.

            /* UPDATE SALES ORDER QTY PICK AND QTY ALLOC AND PICK DATE */
            if so_db <> global_db then do:

               /* UPDATE DETAIL QTY ALL, QTY PICK */
/*L0M0*/       /* ADDED FOURTH INPUT PARAMETER L_DELPROC */
               {gprun.i ""sosopka2.p""
                "(input alc_sod_nbr,
                  input alc_sod_line,
                  input tot_qty_all,
                  input l_delproc)"}
            end.

            /* SWITCH BACK TO THE SALES ORDER DATABASE */
            {gprun.i ""gpalias3.p"" "(so_db, output err_flag)"}

            if err_flag <> 0 and err_flag <> 9 then do:

               /* DATABASE # IS NOT CONNECTED */
/*N0RG*        {mfmsg03.i 2510 4 {&rcslb01_p_1} """" """"} */
/*N0RG*/       {pxmsg.i &MSGNUM=2510 &ERRORLEVEL=4
                        &MSGARG1=getTermLabel(""FOR_SALES_ORDERS"",25)}
               abnormal_exit = true.
               return.
            end.

         end.



         /* UPDATE SOD IN SO DATABASE */
         /* UPDATE DETAIL QTY ALL, QTY PICK */
/*L0M0*/ /* ADDED FOURTH INPUT PARAMETER    */
         {gprun.i ""sosopka2.p""
              "(input alc_sod_nbr,
                input alc_sod_line,
                input tot_qty_all,
                input l_delproc )"}


         /* IF NO ALLOCATIONS AND PRINT ALL OPEN LINES THEN CREATE TEMP REC */
         if total_alloc = 0 and not all_only and open_qty > 0 then do:

            find qad_wkfl where qad_key1 = mfguser + global_db + "stage_list"
            and qad_key2 = sod_nbr + string(sod_line) no-lock no-error.

            if not available qad_wkfl then do:

                find so_mstr where so_nbr = sod_nbr no-lock.
/*J2MH*/        for first pt_mstr
/*J2MH*/            fields (pt_part pt_um)
/*J2MH*/            where pt_part = sod_part no-lock:
/*J2MH*/        end. /* FOR FIRST PT_MSTR */

               create qad_wkfl.

               assign
                qad_key1 = mfguser + global_db + "stage_list"
                qad_key2 = sod_nbr + string(sod_line)
                qad_decfld[1] = 0
                qad_charfld[1] = so_site
                qad_charfld[2] = sod_part
                qad_charfld[6] = so_ship
                qad_charfld[7] = sod_nbr
                qad_charfld[8] = string(sod_line)
/*J2MH*/        qad_charfld[10] = if not l_create_um and available pt_mstr then
/*J2MH*/                            pt_um
/*J2MH*/                         else
/*J2MH*/                            sod_um
/*J2MH*/        qad_charfld[11] = if not l_create_um and available pt_mstr then
/*J2MH*/                            string("1")
/*J2MH*/                         else
/*J2MH*/                            string(sod_um_conv)
/*K003*/        qad_charfld[12] = sod_site
/*K003*/        qad_charfld[13] = shipgrp + "," + inv_mov
/*K003*/        qad_charfld[14] = nrseq + "," + cons_ship.

/*N004*/        if using_seq_schedules and so_seq_order then do:
/*N004*/            /*CREATE SEQ. STAGE LIST ENTRIES (qad_wkfl) */
/*N004*/            {gprunmo.i
                        &program = ""rcslb03.p""
                        &module = "ASQ"
                        &param = """(input sod_nbr,
                                     input sod_line,
                                     input recid(qad_wkfl),
                                     input all_only)"""}
/*N004*/        end.  /* if using_seq_schedules */




            end.
         end.
